package cn.com.jslh.boarpro.main.presenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import net.idik.lib.slimadapter.SlimAdapter;
import net.idik.lib.slimadapter.SlimAdapterEx;
import net.idik.lib.slimadapter.SlimInjector;
import net.idik.lib.slimadapter.viewinjector.IViewInjector;

import cn.com.jslh.boarpro.R;
import cn.com.jslh.boarpro.base.mvp.BaseListPresenter;
import cn.com.jslh.boarpro.base.mvp.BaseListView;
import cn.com.jslh.boarpro.main.model.MenuModelImpl;
import cn.com.jslh.boarpro.main.view.view.MenuFragmentView;
import cn.com.jslh.boarpro.util.ModuleUtil;

/**
 * 作者：周洲 on 2017/7/12 14:22
 * <p>
 * 邮箱：double0zhou@126.com
 */

public class MenuPresenterImpl extends BaseListPresenter{


    private SlimAdapterEx adapter;

    public MenuPresenterImpl(Context context, BaseListView baseListView) {
        super(context, baseListView,new MenuModelImpl(context));
    }

    @Override
    public void upDatas(String... param) {
        adapter.updateData(baseListModel.getDatas(param)).notifyDataSetChanged();
    }

    @Override
    public void setUI(RecyclerView recyclerView, String... param){
        adapter = SlimAdapter.create(SlimAdapterEx.class)
                .enableDiff()
                .registerDefault(R.layout.menu_list_iten, new SlimInjector<ModuleUtil>() {
                    @Override
                    public void onInject(final ModuleUtil moduleUtil, IViewInjector injector) {
                        injector.text(R.id.title, moduleUtil.getMenuName())
                                .clicked(R.id.item_layout, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        ((MenuFragmentView)baseListView).onMenuClickListener(moduleUtil);
                                    }
                                });
                    }
                })
                .attachTo(recyclerView);
    }
}
